package com.zx.mes.feign.hyl.feign.impl;

import com.zx.mes.feign.hyl.feign.RedisWeatherClient;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * RedisWeatherClient feign客户端快速失败实现类
 * @author hyl
 * @date 2018-3-6
 */
@Component
public class RedisWeatherClientFallbackFactory implements FallbackFactory<RedisWeatherClient>{

    private static final Logger logger = LoggerFactory.getLogger(RedisWeatherClientFallbackFactory.class);


    @Override
    public RedisWeatherClient create(final Throwable cause) {
        return new RedisWeatherClient() {
            @Override
            public String setWeatherCache(String key, String jsonStr) {
                logger.info("快速失败原因:{},传参:[key]{},[jsonStr]{}",cause.getMessage(),key,jsonStr);
                return "{\"date\":\"\",\"message\":\"请过几分钟再重试!\",\"status\":500,\"city\":\"\",\"count\":43}";
            }

            @Override
            public String getWeatherCache(String key) {
                logger.info("快速失败原因:{},传参:[key]{}",new Object[]{cause.getMessage(),key});
                return "{\"date\":\"\",\"message\":\"请过几分钟再重试!\",\"status\":500,\"city\":\"\",\"count\":43}";
            }
        };
    }
}
